package com.caldremch.rxretrofit.api;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;

import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.disposables.Disposable;

/**
 * Created by Caldremch on 2017-06-17 01:34
 */

public abstract class BaseActiviy extends AppCompatActivity {


    //用于取消网络请求的
    private CompositeDisposable compositeDisposable;

    public void addDisposable(Disposable disposable) {

        if (compositeDisposable == null) {
            compositeDisposable = new CompositeDisposable();
        }

        compositeDisposable.add(disposable);
    }

    /**
     * 取消网络请求
     */
    public void dispose() {
        if (compositeDisposable != null) {
            compositeDisposable.dispose();
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        // 取消网络请求
        dispose();
    }
}
